﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CardInChina.Web.Mvc
{
    [AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
    public class SessionAuthorizeByAjaxAttribute : FilterAttribute, IActionFilter
    {
        private User user = new User();

        public string AjaxLogInViewPath { get; private set; }

        public SessionAuthorizeByAjaxAttribute()
        {
            AjaxLogInViewPath = "~/Views/Shared/AjaxLogIn.cshtml";
        }

        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //do noting
        }

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (user.IsLogon)
            {
                return;
            }
            else
            {
                filterContext.Result = new ViewResult()
                {
                    ViewName = AjaxLogInViewPath,//post to CustomerController.AjaxLogIn
                    MasterName = null,
                    ViewData = null,
                    TempData = null
                };

            }
        }
    }
}